package com.ruoyi.web.controller.app.controller;

import com.ruoyi.framework.web.exception.base.XResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.sj.domain.Dynamic;
import com.ruoyi.sj.domain.vo.DynamicDetails;
import com.ruoyi.web.controller.app.service.AppDynamicService;
import com.ruoyi.web.core.base.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @ClassName MyDynamicController
 * @Description 我的动态（朋友圈）
 * @Author tyc@yanyu
 * @Date 2018/12/6 0006 17:33
 **/
@RestController
@RequestMapping("/app/md")
@Api(tags = "朋友圈")
public class AppDynamicController extends BaseController {
    @Autowired
    private AppDynamicService myDynamicService;

    @RequestMapping(value = "releaseDynamic", method = RequestMethod.POST)
    @ApiOperation(value = "发布朋友圈", position = 1, notes = "发布朋友圈")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "memberId", value = "用户ID号", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "content", value = "内容", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "picture", value = "图片或者视频", required = false, dataType = "String", paramType = "query")
    })
    public XResult releaseDynamic(@RequestParam @ApiIgnore Map<String, Object> map) {

        return new XResult("发布成功", myDynamicService.addDynamic(map));
    }

    @RequestMapping(value = "queryDynamicList", method = RequestMethod.POST)
    @ApiOperation(value = "查询朋友圈列表", position = 2, response = DynamicDetails.class, notes = "朋友圈列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "第几页", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "每页显示几条数据", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "memberId", value = "用户ID号", required = true, dataType = "String", paramType = "query")
    })
    public XResult queryDynamicList(String memberId, String pageNum, String pageSize) {
        startPage();
        List<DynamicDetails> list = myDynamicService.queryByMemberId(memberId);
        TableDataInfo dataTable = getDataTable(list);
        return new XResult("查询成功", dataTable);
    }

    @RequestMapping(value = "queryAlbumList", method = RequestMethod.POST)
    @ApiOperation(value = "查询用户相册列表", position = 5, response = DynamicDetails.class, notes = "查询用户相册列表")
    @ApiImplicitParam(name = "memberId", value = "用户ID号", required = true, dataType = "String", paramType = "query")
    public XResult queryAlbumList(String memberId) {
        List<DynamicDetails> list = myDynamicService.queryAlbumList(memberId);
        return new XResult("查询成功", list);
    }

    /**
     * 删除用户朋友圈，相应的也要删除这一动态下的评论
     *
     * @return
     */
    @RequestMapping(value = "deleDynamic", method = RequestMethod.POST)
    @ApiOperation(value = "删除朋友圈", position = 3, notes = "删除朋友圈")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "dynamicId", value = "动态id", required = true, dataType = "String", paramType = "query"),
    })
    public XResult deleDynamic(String dynamicId) {
        return new XResult("删除成功", myDynamicService.deleteDynamic(dynamicId));
    }

    /**
     * 所有朋友动态列表
     */
    @PostMapping("getDynamicList")
    @ApiOperation(value = "所有朋友动态列表", position = 4, notes = "所有朋友动态列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "第几页", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "每页显示几条数据", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "memberId", value = "用户ID号", required = true, dataType = "String", paramType = "query")
    })
    public XResult getDynamicList(String memberId) {
        startPage();
        List dynamicList = myDynamicService.getDynamicList(memberId);
        TableDataInfo dataTable = getDataTable(dynamicList);
        return new XResult("操作成功", dataTable);
    }
}
